package com.autumn.sms.service.core.impl;

import com.autumn.sms.service.core.ISmsPlatformService;
import com.autumn.sms.service.vo.PlatformTemplateValue;
import com.autumn.util.ExceptionUtils;
import com.autumn.util.StringUtils;
import com.autumn.util.TypeUtils;

/**
 * 抽象服务
 * 
 * @author 老码农
 *
 *         2018-01-12 19:16:24
 */
public abstract class AbstractSmsPlatformService implements ISmsPlatformService {

	/**
	 * 获取配置信息
	 * 
	 * @param platformTemplate
	 * @param key
	 * @param targetClass
	 * @param isMust
	 * @return
	 *
	 */
	protected <T> T checkConfigInfo(PlatformTemplateValue platformTemplate, String key, Class<T> targetClass,
			boolean isMust) {
		Object value = platformTemplate.getConfigInfoMap().get(key);
		boolean isNullOrBlank = value == null || StringUtils.isNullOrBlank(value.toString());
		if (isNullOrBlank && isMust) {
			ExceptionUtils.throwValidationException(
					"发送平台 " + platformTemplate.getPlatformName() + " 的配置参数 " + key + " 值为 null");
		}
		return TypeUtils.toConvert(targetClass, value);
	}

}
